Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This technically fixes the mypy error seen in
channels.py
, but I'm not sure if it's the best fix. IMO it simply masks the symptom rather than fixes the root cause. I think more refactoring and architecture changes might be needed to fix the root issue.I also move the type hints to
component.Component.__init__
as that's common practice.One of the issues is that the
stringparser
library doesn't have type annotations, so mypy setsparser
toAny
here:pyvisa-sim/pyvisa_sim/channels.py
Line 187 in b0c2282
and then
parsed
toAny
here:pyvisa-sim/pyvisa_sim/channels.py
Line 189 in b0c2282
From there, the
isinstance
statement end up doing type narrowing toDict[Any, Any]
which then getsUnion
'd withAny
from before.The issue is that the
self.set_value
function doesn't acceptAny
. Based on my (possibly flawed) understanding of the code, it looks like it's safe enough to just convert to a string before callingset_value
. So that's what I do.In addition, I ran a temporary backport of this change to v0.5.1 and ran my tests for a separate project that uses
pyvisa-sim
, and those still ran OK so... I guess it's OK?